package org.academic.texteditor.gui.feature;

import java.awt.Color;
import java.awt.Dimension;

import javax.swing.text.Style;
import javax.swing.text.StyleConstants;

import org.academic.texteditor.gui.component.PersonalizedTextPane;

public class Text extends Feature {

	private static final long serialVersionUID = 3380482836656375192L;
	
	private final PersonalizedTextPane textPane;

	public Text() {
		setLayout(null);
		
		textPane = new PersonalizedTextPane();
		add(textPane);
		
		Style defaultStyle = textPane.getStyle("default");
		Style markStyle = textPane.addStyle("Mark", defaultStyle);
		StyleConstants.setBackground(markStyle, Color.YELLOW);
	}

	public PersonalizedTextPane getTextPane() {
		return textPane;
	}

	@Override
	public void setSize(int width, int height) {
		super.setSize(width, height);
		resize();
	}
	
	@Override
	public void setSize(Dimension dimension) {
		super.setSize(dimension);
		resize();
	}
	
	@Override
	public void setBounds(int x, int y, int width, int height) {
		super.setBounds(x, y, width, height);
		resize();
	}
	
	private void resize() {
		textPane.setBounds(2, 2, getWidth() - 4, getHeight() - 4);
		textPane.setMaximumSize(getSize());
	}
	
}
